const state = {
    courseId: null, // 课程ID
    courseInfo: {}, // 课程信息
    courseTree: null, // 课程章节树
    courseCatalogId: null, // 课程章节ID
    courseCatalogInfo: {}, // 课程章节信息
    courseWordPath: '', // 课程文档地址
    // courseWordPath: 'http://192.168.200.105:1315/group1/M00/00/D8/wKgAnV4GOdyAFD59AOPAAAEDHxk183.ppt', // 课程文档地址
    courseVideoPath: '', // 课程视频地址
    courseUploadFileSet: null
}

const mutations = {
    SET_COURSEID: (state, id) => { //
        state.courseId = id
    },
    SET_COURSEINFO: (state, info) => {
        state.courseInfo = info
    },
    SET_COURSETREE: (state, data) => {
        state.courseTree = data
    },
    SET_COURSECATALOGID: (state, id) => {
        state.courseCatalogId = id
    },
    SET_COURSECATALOGINFO: (state, info) => {
        state.courseCatalogInfo = info
    },
    SET_COURSEWORDPATH: (state, value) => {
        state.courseWordPath = value
    },
    SET_COURSEVIDEOPATH: (state, value) => {
        state.courseVideoPath = value
    },
    SET_COURSEUPLOADFILESET: (state, value) => {
        state.courseUploadFileSet = value
    }
}

const actions = {
    courseId({
        commit
    }, id) {
        commit('SET_COURSEID', id)
    },
    courseInfo({
        commit
    }, info) {
        commit('SET_COURSEINFO', info)
    },
    courseTree({
        commit
    }, data) {
        commit('SET_COURSETREE', data)
    },
    courseCatalogId({
        commit
    }, id) {
        commit('SET_COURSECATALOGID', id)
    },
    courseCatalogInfo({
        commit
    }, info) {
        commit('SET_COURSECATALOGID', info.courseCatalogId)
        commit('SET_COURSECATALOGINFO', info)
    },
    courseWordPath({
        commit
    }, value) {
        if (value.indexOf('http') > -1) {
            console.log(value)
            commit('SET_COURSEWORDPATH', value)
        } else {
            commit('SET_COURSEWORDPATH', process.env.VUE_APP_WAREHOUSE_API + value)
        }
    },
    courseVideoPath({
        commit
    }, value) {
        if (value.indexOf('http') > -1 || value === '' || value === 'reSet') {
            commit('SET_COURSEVIDEOPATH', value)
        } else {
            commit('SET_COURSEVIDEOPATH', process.env.VUE_APP_WAREHOUSE_API + value)
        }
    },
    courseUploadFileSet({
        commit
    }, value) {
        commit('SET_COURSEUPLOADFILESET', value)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}